package com.nbsaas.boot.vipcard.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;
import java.util.Date;


@SearchBean(items = {
        @SearchItem(label = "姓名",name = "name",key = "user.name"),
        @SearchItem(label = "手机号",name = "phone",key = "user.phone")
})
@Data
@FormAnnotation(title = "会员卡号", menu = "1,76,111",viewWidth = "100")
@Entity
@Table(name = "bs_vip_card")
public class VipCard extends AbstractEntity {

    @Comment("会员卡号")
    @SearchItem(label = "会员卡号",name = "cardNo")
    @FormField(title = "会员卡号", sortNum = "3", grid = true, col = 22, type = InputType.date)
    @Column(length = 32, unique = true, name = "no")
    private String cardNo;

    @Comment("会员卡模板id")
    @SearchItem(label = "会员卡",name = "card",key = "card.id",classType = Long.class,operator = Operator.eq,type = InputType.select)
    @FieldName
    @FieldConvert
    @FormField(title = "会员卡", sortNum = "3", grid = true, type = InputType.select,option = "card")
    @ManyToOne(fetch = FetchType.LAZY)
    private VipCardTemplate card;

    @Comment("会员用户id")
    @FormField(title = "会员姓名", sortNum = "3", grid = true, type = InputType.select,option = "user")
    @FieldConvert
    @FieldName
    @OneToOne(fetch = FetchType.LAZY)
    private User owner;

    @Comment("开始时间")
    @FormField(title = "开始时间", sortNum = "3", grid = true,type = InputType.date,width = "160",sort = true)
    private Date beginDate;

    @Comment("结束时间")
    @FormField(title = "结束时间", sortNum = "4", grid = true,type = InputType.date,width = "160")
    private Date endDate;

    /**
     * 会员卡状态
     */
    @Comment("会员卡状态")
    private Integer state;

}
